<?php include_once 'Pecahan/sessionLontong.php'; ?>
<?php
if (isset($_GET['name_viewed'])!= NULL) {
    $name_viewed = $_GET['name_viewed'];
}
else if (isset($_SESSION['user_name'])!= NULL) {
    $name_viewed = $_SESSION['user_name'];
}
if (isset($_SESSION['user_name'])!= NULL) {
    $name_logon = $_SESSION['user_name'];
    $temp = new login();
    $role = $temp->getRole($name_logon );
}
else {
    $name_logon = NULL;
    $role = NULL;
}
?>
<?php
include_once'controller/registrasi.php';
include_once'controller/login.php';
include_once 'controller/follow.php';
include_once 'controller/photo.php';

$getID = new photo();
$photo_id = $getID->showPhotoID($name_viewed, $_GET['url_foto']);
if(isset ($_POST['sendComPhotoButton'])) {
    $getID->addPhotoCom($name_viewed, $_GET['url_foto'], $name_logon, $_POST['bodymessage']);
}
if(isset ($_GET['likes'])) {
    if(!$getID->isHasScored($photo_id, $name_logon)) {
        if(($_GET['likes']) == 'yes') {
            $int = 1;
            $getID->addPhotoVal($name_viewed, $_GET['url_foto'], $name_logon, $int);
        }
        else if (($_GET['likes']) == 'no') {
            $int = -1;
            $getID->addPhotoVal($name_viewed, $_GET['url_foto'], $name_logon, $int);
        }
        else if (($_GET['likes']) == 'neutral') {
            $int = 0;
            $getID->addPhotoVal($name_viewed, $_GET['url_foto'], $name_logon, $int);
        }
    }
}
if (isset ($_POST['submit_button_save'])) {
    $updateFoto = new photo();
    $updateFoto->editPhoto('1', $_SESSION['user_name'], $_GET['url_foto'], $_POST['dekripsi']);
    $updateFoto->editPhoto('2', $_SESSION['user_name'], $_GET['url_foto'], $_POST['kata_kunci']);
    $updateFoto->editPhoto('3', $_SESSION['user_name'], $_GET['url_foto'], $_POST['tanggal']);
    $updateFoto->editPhoto('5', $_SESSION['user_name'], $_GET['url_foto'], $_POST['kategori']);
    $updateFoto->editPhoto('6', $_SESSION['user_name'], $_GET['url_foto'], $_POST['penglihat']);
    $updateFoto->editPhoto('7', $_SESSION['user_name'], $_GET['url_foto'], $_POST['penglihatKom']);
}
if (isset($_POST['donetagging'])) {
    $tagFoto = new photo();
    foreach ($_POST['usertotag'] as $i) {
        $tagFoto->addPhotoTag($name_logon, $_GET['url_foto'], $i);
    }
}
?>
<?php $judul = 'Foto Zoom'; ?>
<?php include_once 'Pecahan/header.php'; ?>

<div id ="content" class="isipage">
    <div class="isipagestandar">
        <div>
            <label id="titlebold"><?php echo 'Albumnya '.$name_viewed;  ?></label>
        </div>
        <div class="arrowphoto">
            <?php
            if($name_logon == $name_viewed || $role == 'admin') {
                $urlbaru = 'foto_album.php?name_viewed='.$name_logon.'&delete=yes'.'&url_foto='.$_GET['url_foto'];
                echo'<a href='.$urlbaru.'><img id="like" src="images/hapus.png" alt="hapus" border="0"/></a>';
            }
            ?>
            <label>   </label>
            <?php
            if($name_logon == $name_viewed) {
                $urlbaru = 'foto_edit.php?name_viewed='.$name_logon.'&url_foto='.$_GET['url_foto'];
                echo'<a href='.$urlbaru.'><img id="like" src="images/edit.png" alt="hapus" border="0" height="40" width="40"/></a>';
            }
            ?>
            <label>   </label>
            <?php
            if($name_logon == $name_viewed) {
                $urlbaru = 'fototagging.php?name_viewed='.$name_logon.'&url_foto='.$_GET['url_foto'];
                echo'<a href='.$urlbaru.'><img id="like" src="images/tag.png" alt="hapus" border="0" height="40" width="40"/></a>';
            }
            ?>

        </div>
        <div class="photozoom">
            <?php
            echo'<img src="'.$_GET['url_foto'].'" alt="photozoom" height="500" width="700" border="0"/>';
            ?>
        </div>
        <div class ="arrowphoto">
            <?php
            if($role != NULL && $name_logon == $name_viewed) {
                $urlProfile = "profil.php?name_viewed=".$name_logon."&newPhoto=";
                echo'<a href='.$urlProfile.$_GET['url_foto'].'><img id="makeprofpic" src="images/makeprofpic.png" alt="make profile picture" border="0"/></a>';
            }
            ?>
        </div>
        <div class ="arrowphoto">
            <div>
                <?php
                $nilai = new photo();
                $tempNilai = $nilai->showSumPhotoVal($name_viewed,$_GET['url_foto'] );
                echo'<h4>Nilai : '.$tempNilai.'</h4>';
                ?>
            </div>
            <span>
                <?php
                if($role != NULL && $name_logon != $name_viewed) {
                    $urlbaru = 'foto_zoom.php?name_viewed='.$name_viewed.'&url_foto='.$_GET['url_foto'].'&likes=yes';
                    echo'<a href='.$urlbaru.'><img id="like" src="images/thumbup.png" alt="like" border="0"/></a>';
                }
                ?>
                <label>   </label>
            </span>
            <span>
                <?php
                if($role != NULL && $name_logon != $name_viewed) {
                    $urlbaru = 'foto_zoom.php?name_viewed='.$name_viewed.'&url_foto='.$_GET['url_foto'].'&likes=neutral';
                    echo'<a href='.$urlbaru.'><img id="neutral" src="images/neutral_hand.png" alt="neutral" border="0"/></a>';
                }
                ?>
                <label>   </label>
            </span>
            <span>
                <?php
                if($role!= NULL && $name_logon != $name_viewed) {
                    $urlbaru = 'foto_zoom.php?name_viewed='.$name_viewed.'&url_foto='.$_GET['url_foto'].'&likes=no';
                    echo'<a href='.$urlbaru.'><img id="dislike" src="images/thumbdown.png" alt="like" border="0"/></a>';
                }
                ?>
            </span>
        </div>
    </div>
    <div class="space">

    </div>
    <div class="isipagestandar">
        <div>
            <label class="labelinput" id="titlebold">Description: </label>
            <label class="input" id="desc"><?php echo $getID->getPhotoDesc($photo_id); ?></label>
        </div>
        <div class="space"></div>
        <div>
            <label class="labelinput" id="titlebold">Keyword: </label>
            <label class="input" id="keyword"><?php echo $getID->getKeyWord($photo_id); ?></label>
        </div>
        <div class="space"></div>
        <div>
            <label class="labelinput" id="titlebold">Category: </label>
            <label class="input" id="category"><?php echo  $getID->getCategory($photo_id); ?></label>
        </div>
        <div class="space"></div>
        <div>
            <label class="labelinput" id="titlebold">Captured: </label>
            <label class="input"><?php echo $getID->getCaptDate($photo_id); ?></label>
        </div>
        <div class="space"></div>
        <div>
            <label class="labelinput" id="titlebold">Uploaded: </label>
            <label class="input"><?php echo  $getID->getPostDate($photo_id); ?></label>
        </div>
        <div class="space"></div>
        <div>
            <?php
            $resultTags = $getID->showPhotoTag($name_viewed, $_GET['url_foto']);
            if (mysql_num_rows($resultTags) > 0) {
                echo '<label class="labelinput" id="titlebold">Taggs: </label>';
                while ($rowTag = mysql_fetch_array($resultTags)) {
                    ?>
            <label class="input"><a href="profil.php?name_viewed=<?php echo $rowTag['user_name']?>"><?php echo $rowTag['user_name']; ?></a>,</label>
                    <?php
                }
            }
            ?>
        </div>
        <div class="space"></div>
    </div>
    <div class="space">

    </div>
</div>
<div class="isipage">
    <?php
    if (($getID->getPhotoComPrev($photo_id) == "all_user") || (($getID->getPhotoComPrev($photo_id) == "owner") && ($name_logon == $getID->getUserName($photo_id)))) {
        ?>
    <div class="isipagestandar">
        <form action=<?php $urlANYAR = 'foto_zoom.php?name_viewed='.$name_viewed.'&url_foto='.$_GET['url_foto'];
                  echo '"'.$urlANYAR.'"'; ?> method="post">
            <div>
                <label id="titlebold">Your comment:</label>
            </div>
            <div class="space">

            </div>
            <div>
                <textarea class="input" name="bodymessage" id="photocommentarea" cols="40" rows="100"></textarea>
            </div>
            <div>
                <input id="commentbutton" name="sendComPhotoButton" type="submit" value="Send" />
            </div>
            <div class="space">

            </div>
        </form>
    </div>
        <?php } ?>
    <div class="isipagestandar">
        <div>
            <label id="titlebold"> Recent Comments: </label>
        </div>
        <div class="space"></div>
        <?php
        include_once 'controller/photo.php';
        $listPhotos = new photo();
        $resultCom = $listPhotos->showPhotoCom($name_viewed, $_GET['url_foto']);
        $iterate=0;
        while($row = mysql_fetch_array($resultCom)) {
            $iterate++;
            $userCom = $row['user_name'];
            $bodyCom = $row['body'];
            ?>
        <div>
            <label class="labelinput" id="bold"> <?php echo $userCom?> </label>
            <label class="input"><?php echo $bodyCom?></label>
        </div>
            <?php } ?>
    </div>
</div>
<?php include_once 'Chat/chat.php';?>
<?php include_once 'Pecahan/footer.php'; ?>